<template>
  <FormView
    v-model="entity"
    :title="entity.id ? '{{formName}}' : '新建{{formName}}'"
    :toolbar-attrs="{
      buttons: [
        'back',
        {
          save: isDraft || flowContext.isStartNode,
          submit: hasBtn('submit'),
          withdraw: flowContext.canWithdraw,
          reject: flowContext.canReject,
          finish: hasBtn('finish')
        }
      ]
    }"
    :toolbar-listeners="{
      save: () => saveAndStart({ title: `${userName}的{{formName}}申请` }),
      submit: submitAudit,
      finish: () => submitAudit({}),
      withdraw: () => withdrawAudit(),
      reject: () => reject()
    }">
    <template #toolbar-right> </template>
    <FormHolder ref="form" label-width="130px" :disabled="isDisabled" :model="entity">
      <FormItemGroup block-title="基本信息">{{#each columns}}{{form dataType maxLength prop label form}}{{/each}}
      </FormItemGroup>
    </FormHolder>
  </FormView>
</template>

<script>
  import { save, create, load, update } from './api'
  import flowForm from '@/vue/mixin/flow-form'

  export default {
    name: '{{frontendFilePrefix}}Form',
    docType: '{{docType}}',
    relativeViewId: '{{frontendFilePrefix}}View',
    mixins: [flowForm],
    data() {
      return {
        entity: {
{{#each columns}}
         {{prop}}: null,
{{/each}}
        }
      }
    },
    methods: {
      create,
      load,
      save,
      update,
      async initEntity(id) {
        const entity = await this.loadEntity(id)
        entity.books = entity.books || []
        this.entity = entity
      }
    }
  }
</script>
